home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 90 / MacAddict_090_2004-02.iso / mac / Software / Utilities / Speed Download 2.1.2.dmg / Speed Download 2 / sdcli < prev   
Text File  |  2003-11-04  |  11KB  |  272 lines

  1. #!/bin/sh
  2. #
  3. #Very simple script illustrating how SD can be controlled from the command line
  4. #Don't hesitate to modify it, do tell us if you make some useful mods
  5. #
  6. #
  7. #
  8. #
  9.  
  10. if [ "$1" = 'dl' ];
  11. then
  12.     if [ "$#" -lt 2 ]; then
  13.         echo "Missing url"
  14.     else
  15.         #add the item
  16.         uid=`osascript -e 'tell application "Speed Download 2"'  -e "AddURL \"$2\"" -e 'end tell'` 
  17.         #get it
  18.         res=`osascript -e 'tell application "Speed Download 2"' -e "StartQueuedDownload $uid" -e 'end tell'`
  19.         if [ "$res" -eq -1 ]; then
  20.             echo "Too many downloads active, download queued with uid $uid"
  21.         else
  22.             echo "Download starting, uid for this download is $uid"
  23.         fi
  24.     fi
  25. elif [ "$1" = 'launch' ]; then
  26.         echo `osascript -e 'tell application "Speed Download 2"' -e "activate" -e 'end tell'`
  27. elif [ "$1" = 'startq' ]; then
  28.                 osascript -e 'tell application "Speed Download 2"' -e "StartQueue" -e 'end tell' >/dev/null
  29.         echo "Queue started"
  30. elif [ "$1" = 'stopq' ]; then
  31.                 osascript -e 'tell application "Speed Download 2"' -e "StopQueue" -e 'end tell' >/dev/null
  32.                 echo "Queue stopped"    
  33.  
  34. elif [ "$1" = 'info' ]; then
  35.     if [ "$#" -lt 2 ]; then
  36.                 echo "missing uid"
  37.         else
  38.         echo `osascript -e 'tell application "Speed Download 2"' -e "GetDownloadInfo $2" -e 'end tell'`
  39.     fi
  40. elif [ "$1" = 'add' ]; then
  41.         if [ "$#" -lt 2 ]; then
  42.                 echo "missing url"
  43.         else
  44.                 uid=`osascript -e 'tell application "Speed Download 2"' -e "AddURL \"$2\" startqueue false" -e 'end tell'`
  45.         echo "Item added with uid: $uid"
  46.         fi
  47. elif [ "$1" = 'start' ]; then
  48.         if [ "$#" -lt 2 ]; then
  49.                 echo "missing uid"
  50.         else
  51.                 res=`osascript -e 'tell application "Speed Download 2"' -e "StartQueuedDownload $2" -e 'end tell'`
  52.             if [ $res -eq 0]; then
  53.             echo "Download started"
  54.         elif [ $res -eq -4]; then
  55.             echo "bad uid"
  56.         elif [ $res -eq -1]; then
  57.             echo "too many active downloads"
  58.         fi
  59.     fi
  60. elif [ "$1" = 'stop' ]; then
  61.         if [ "$#" -lt 2 ]; then
  62.                 echo "missing uid"
  63.         else
  64.                 res=`osascript -e 'tell application "Speed Download 2"' -e "CancelDownload $2" -e 'end tell'`
  65.             if [ $res -eq 0 ]; then
  66.             echo "Download removed"
  67.         else echo "Invalid uid"
  68.         fi
  69.     fi
  70. elif [ "$1" = 'remove' ]; then
  71.         if [ "$#" -lt 2 ]; then
  72.                 echo "missing uid"
  73.         else
  74.                 res=`osascript -e 'tell application "Speed Download 2"' -e "Remove $2" -e 'end tell'`
  75.             if [ $res -eq 0 ]; then
  76.             echo "0:element removed";
  77.         elif [ $res -eq -1 ]; then
  78.             echo "-1:element could not be removed because it is in use"
  79.         else
  80.             echo "-2:bad uid"
  81.         fi
  82.     fi
  83. elif [ "$1" = 'clear' ]; then
  84.     res=`osascript -e 'tell application "Speed Download 2"' -e "Clearqueue" -e 'end tell'`
  85.     if [ $res -eq 0 ]; then
  86.         echo "Queue Cleared"
  87.     else
  88.         echo "Queue could not be cleared. elements may be in use"
  89.     fi
  90.  
  91.  elif [ "$1" = 'url' ]; then
  92.         if [ "$#" -lt 2 ]; then
  93.                 echo "missing uid"
  94.         else
  95.                 res=`osascript -e 'tell application "Speed Download 2"' -e "GetDownloadURL $2" -e 'end tell'`
  96.         if [ "$res" = "" ]; then
  97.             echo "Invalid uid"
  98.         else echo $res
  99.         fi
  100.         fi
  101. elif [ "$1" = 'quit' ]; then
  102.     echo `osascript -e 'tell application "Speed Download 2"' -e "quit" -e 'end tell'`
  103. elif [ "$1" = 'list' ]; then
  104.         osascript -e 'tell application "Speed Download 2"' -e "ListQueue" -e 'end tell'
  105. elif [ "$1" = 'listFolder' ]; then    
  106.      if [ "$#" -lt 2 ]; then
  107.                 echo "missing folder id"
  108.         else
  109.         osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents $2" -e 'end tell'
  110.     #    if [ "$res" = "" ]; then
  111.         #                echo "Invalid folder id"
  112.         #        else echo $res
  113.         #        fi
  114.     fi
  115. elif [ "$1" = 'listMain' ]; then
  116.     osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents 1" -e 'end tell'
  117. elif [ "$1" = 'listVT' ]; then
  118.         osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents 8" -e 'end tell'
  119. elif [ "$1" = 'folders' ]; then
  120.         osascript -e 'tell application "Speed Download 2"' -e "ListFolders" -e 'end tell' 
  121. elif [ "$1" = 'rfolders' ]; then
  122.      if [ "$#" -lt 2 ]; then
  123.                 echo "missing host id"
  124.         else
  125.                 osascript -e 'tell application "Speed Download 2"' -e "ListRemoteFolders $2" -e 'end tell'
  126.                 
  127.         fi
  128. elif [ "$1" = 'listRfolder' ]; then
  129.          if [ "$#" -lt 3 ]; then
  130.                 echo "missing host id,uid"
  131.         else
  132.                 osascript -e 'tell application "Speed Download 2"' -e "ListRemoteFolderContents $3 host id $2" -e 'end tell'
  133.                 
  134.                 
  135.         fi                 
  136. elif [ "$1" = 'listR' ]; then
  137.          if [ "$#" -lt 2 ]; then
  138.                 echo "missing host id"
  139.         else
  140.                 osascript -e 'tell application "Speed Download 2"' -e "ListRemoteQueue $2" -e 'end tell'
  141.                 
  142.         fi
  143.  
  144. elif [ "$1" = 'connect' ]; then
  145.          if [ "$#" -lt 2 ]; then
  146.                 echo "missing server address"
  147.         else
  148.                 res=`osascript -e 'tell application "Speed Download 2"' -e "ConnectHost \"$2\" user \"$3\" password \"$4\" " -e 'end tell'`
  149.                 if [ $res -eq 0 ]; then
  150.                         echo "Connection in progress"
  151.                 else echo "Connection attempt failed"
  152.                 fi
  153.         fi
  154.  
  155. elif [ "$1" = 'disconnect' ]; then
  156.          if [ "$#" -lt 2 ]; then
  157.                 echo "missing host id"
  158.         else
  159.                 res=`osascript -e 'tell application "Speed Download 2"' -e "DisconnectHost \"$2\"" -e 'end tell'`
  160.                 if [ $res -eq -1 ]; then 
  161.                         echo "Invalid host ID"
  162.                 else echo "Disconnected"
  163.         fi
  164.     fi
  165. elif [ "$1" = 'refreshHost' ]; then
  166.          if [ "$#" -lt 2 ]; then
  167.                 echo "missing host id"
  168.         else
  169.                 res=`osascript -e 'tell application "Speed Download 2"' -e "RefreshHost $2" -e 'end tell'`
  170.                 if [ $res -eq -1 ]; then
  171.                         echo "Invalid host ID"
  172.                 else echo "refreshing..."
  173.                 fi
  174.                         
  175.         fi
  176. elif [ "$1" = 'listH' ]; then 
  177.     res=`osascript -e 'tell application "Speed Download 2"' -e "ListHosts" -e 'end tell'`
  178.         echo $res
  179. elif [ "$1" = 'connectS' ]; then
  180.     if [ "$#" -lt 2 ]; then
  181.                 echo "missing server name"
  182.     else
  183.                 res=`osascript -e 'tell application "Speed Download 2"' -e "ConnectFavourite \"$2\"" -e 'end tell'`
  184.                 if [ $res -eq -1 ]; then
  185.                         echo "Invalid server name"
  186.                 else echo "connection in progress"
  187.                 fi
  188.         fi
  189. elif [ "$1" = 'listS' ]; then
  190.         osascript -e 'tell application "Speed Download 2"' -e "ListFavourites" -e 'end tell'
  191.         
  192. elif [ "$1" = 'saveS' ]; then
  193.          if [ "$#" -lt 2 ]; then
  194.                 echo "missing host id"
  195.         else
  196.                 res=`osascript -e 'tell application "Speed Download 2"' -e "AddHostToFavourites $2" -e 'end tell'`
  197.         if [ $res -eq -1 ]; then
  198.                         echo "Invalid host ID"
  199.                 else echo "added"
  200.                 fi
  201.         fi
  202. elif [ "$1" = 'removeS' ]; then
  203.         if [ "$#" -lt 2 ]; then
  204.                 echo "missing server name"
  205.         else
  206.                 res=`osascript -e 'tell application "Speed Download 2"' -e "RemoveFavourite \"$2\"" -e 'end tell'`
  207.                 if [ $res -eq -1 ]; then
  208.                         echo "Invalid server name"
  209.                 else echo "removed"
  210.                 fi
  211.         fi
  212.  
  213. elif [ "$1" = 'addRemote' ]; then
  214.     
  215.         if [ "$#" -lt 3 ]; then
  216.                 echo "missing hostID, uid"
  217.         else
  218.            res=`osascript -e 'tell application "Speed Download 2"' -e "AddRemoteItemToQueue $3 host id $2" -e 'end tell'`
  219.                 if [ "$res" = "0" ]; then
  220.                         echo "Invalid hostID/uid"
  221.                 else echo "Item added with uid $res"
  222.                 fi
  223.         fi
  224. elif [ "$1" = 'ddl' ]; then
  225.         
  226.         if [ "$#" -lt 3 ]; then
  227.                 echo "missing hostID, uid"
  228.         else
  229.               res=`osascript -e 'tell application "Speed Download 2"' -e "AddDirectTransfer $2 UID $3" -e 'end tell'`
  230.                 if [ "$res" = "0" ]; then
  231.                         echo "Invalid hostID/uid"
  232.                 else echo "Item added with uid $res"
  233.                 fi
  234.         fi
  235.    
  236. elif [ "$1" = 'bwstats' ]; then
  237.     osascript -e 'tell application "Speed Download 2"' -e "BWstats" -e 'end tell'
  238. else
  239.     echo "usage:"
  240.     echo "sdcli launch            opens Speed Download 2"
  241.     echo "sdcli dl <url>            downloads the specified url, returns a uid"
  242.     echo "sdcli add <url>            Adds the specified url to the queue, without downloading it, returns a uid"
  243.     echo "sdcli stop <uid>        cancels the download corresponding to the uid"
  244.     echo "sdcli start <uid>        starts the download corresponding to the uid"
  245.     echo "sdcli remove <uid>        removes the download corresponding to the uid"
  246.     echo "sdcli clear            removes all downloads"
  247.     echo "sdcli info <uid>        returns a status string for the specified uid"
  248.     echo "sdcli url <uid>            returns the url for the specified uid"
  249.     echo "sdcli list            lists all uids and and urls on the local machine"
  250.     echo "sdcli startq            starts the queue"
  251.     echo "sdcli stopq             stops the queue"
  252.     echo "sdcli quit            quit Speed Download 2"
  253.     echo "sdcli listFolder <uid>        lists the contents of the local folder with the specified uid"
  254.     echo "sdcli listMain            lists the contents of my downloads"
  255.     echo "sdcli listVT            lists the contents of the VersionTracker folder"
  256.     echo "sdcli folders            lists the local folders"
  257.     echo "sdcli listRFolder <hostID> <uid> lists the contents of the folder with uid <uid> on the host specified"
  258.     echo "sdcli listR <hostID>        lists all the urls on the specified remote host"
  259.     echo "sdcli rfolders <hostID>        lists the folders on the specified host"
  260.     echo "sdcli connect <address>        initiates a connection to the specified address"
  261.     echo "sdcli disconnect <hostID>    disconnects the specified connection"
  262.     echo "sdcli listH            lists active connections"
  263.     echo "sdcli connectS <name>        connects the named server from my servers"
  264.     echo "sdcli listS            lists the servers in my servers, and their status"    
  265.     echo "sdcli saveS <hostID>         saves the specified connection in my servers"
  266.     echo "sdcli removeS <name>         removes the named entry from my servers"
  267.     echo "sdcli addRemote <hostID> <uid>     adds the specified download from a remote host to the local host"
  268.     echo "sdcli refreshHost <hostID>     refreshes the specified host"
  269.     echo "sdcli bwstats        Displays bandwidth usage"
  270.     echo "sdcli ddl <hostID> <uid>        adds the specified download from a remote host to the local host as a direct transfer"
  271. fi
  272.